package com.chris.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chris.blog.dao.UserDao;
import com.chris.blog.entity.po.UserPO;
import com.chris.blog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDAO;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return userDAO.deleteByPrimaryKey(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int insert(UserPO record) {
        return userDAO.insert(record);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int insertSelective(UserPO record) {
        return userDAO.insertSelective(record);
    }

    @Override
    public UserPO selectByPrimaryKey(Integer id) {
        return userDAO.selectByPrimaryKey(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updateByPrimaryKeySelective(UserPO record) {
        return userDAO.updateByPrimaryKeySelective(record);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updateByPrimaryKey(UserPO record) {
        return userDAO.updateByPrimaryKey(record);
    }

    @Override
    public UserPO findUserByNme(String username) {
        QueryWrapper<UserPO> queryWrapper = new QueryWrapper();
        queryWrapper.eq("username", username);
        return userDAO.selectOne(queryWrapper);
    }

    public UserPO findUserByUid(String uid) {
        return userDAO.findUserByUid(uid);
    }
}
